package com.fwx.chatroom.config;

import com.fwx.chatroom.controller.WebSocketController;
import com.fwx.chatroom.testWeb.TestWebSocketController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

@Configuration
/*启动webSocket*/
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private TestWebSocketController testWebSocketController;

    @Autowired
    private WebSocketController webSocketController;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //把刚才创建好的类注册到具体路径上
        registry.addHandler(testWebSocketController,"/test");
        registry.addHandler(webSocketController,"/WebSocketMessage")
                //将用户在HttpSession中添加的键值对向webSocket里添加一份
                .addInterceptors(new HttpSessionHandshakeInterceptor());
    }
}
